package com.logictech.lims.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import com.logictech.lims.service.LocationService;
import com.logictech.lims.service.LogService;
import com.logictech.lims.entity.Location;
import com.logictech.lims.dao.LocationDao;

@Service("locationService")
public class LocationServiceImpl implements LocationService {
	@Resource
	private LocationDao locationDao;
	
	@Resource
	private LogService logService;

	@Override
	public void doAdd(Location location) {
		locationDao.add(location);
		logService.doAdd("1",location);
	}

	@Override
	public void doEdit(Location location) {
		locationDao.update(location);
		logService.doAdd("2",location);
	}

	@Override
	public void doDelete(String id) {
		Location location  = locationDao.get(id);
		logService.doAdd("3",location);
		location.setDeleteFlag("1");
		locationDao.update(location);
	}

	@Override
	public Location queryById(String id) {
		Location location  = locationDao.get(id);
		return location;
	}

	@Override
	public PageList<Location> queryPageList(
		PageQuery<Location> pageQuery) {
		PageList<Location> result = new PageList<Location>();
		Integer itemCount = locationDao.count(pageQuery);
		List<Location> list = locationDao.queryPageList(pageQuery,itemCount);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}
	
	@Override
	public List<Location> queryAll() {
		return locationDao.queryAll();
	}
	
}
